package agent.ccs
import cwb.Value
import scala.collection.SortedSet
import scala.collection.mutable.HashMap
import scala.collection.immutable.TreeSet

class Restriction(vals: List[Value]) {
  var set = SortedSet(vals: _*)
   
  def restrictionString: String = {
    if (set.size > 0) {
      var string = set.head.valueOf
      for(x <- set.takeRight(set.size - 1)) string += "," + x.valueOf
      if (set.size > 1) {
        "{" + string + "}"
      } else {
        //println(string)
        string
      }
    } else ""
  }
  
  override
  def equals(rhs: Any) = {
    rhs match {
      case re: Restriction => re.set == set
      case _ => false
    }
  }
  
  def allows(action: CCSAction): Boolean = {
    //for (v <- set) yield println(v.valueOf)
    //println(set)
    action match {
      case act: Act => !set.contains(new Value(act.port))
      case _ => true
    }
  }
}